﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;
using Microsoft.Office.Interop.Excel;

namespace WindowsFormsApplication1
{
    public partial class frmNhanVien : Form
    {
        NhanVienBUS NV_BUS = new NhanVienBUS();
        NhanVienDTO NV_DTO = new NhanVienDTO();
        public frmNhanVien()
        {
            InitializeComponent();
        }

        private void frmNhanVien_Load(object sender, EventArgs e)
        {

            dataGridView1.DataSource = NV_BUS.Hien_DSNV();
            txtMaNV.Text = NV_BUS.Phatsinh_MaNV();
            NV_BUS.khoitao_KN();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            NV_BUS.khoitao_KN();
            txtMaNV.Text = NV_BUS.Phatsinh_MaNV();
            NV_DTO.Manv = txtMaNV.Text;
            NV_DTO.Tennv = txtHoTen.Text;
            NV_DTO.Ngaysinh = dateTimePicker1.Value;
            NV_DTO.Diachi = txtDiaChi.Text;
            NV_DTO.Dienthoai = txtDienThoai.Text;
            NV_DTO.Machucvu = txtMaChucVu.Text;
            NV_DTO.Mabophan = txtMaBoPhan.Text;
            try
            {
                NV_BUS.them_nhanVien(NV_DTO);
            }
            catch
            {
                MessageBox.Show("ban nhap khong dung thong tin","thong bao");
            }
            frmNhanVien_Load(sender, e);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            NV_DTO.Manv = txtMaNV.Text;
            NV_DTO.Tennv = txtHoTen.Text;
            NV_DTO.Ngaysinh = dateTimePicker1.Value;
            NV_DTO.Diachi = txtDiaChi.Text;
            NV_DTO.Dienthoai = txtDienThoai.Text;
            NV_DTO.Machucvu = txtMaChucVu.Text;
            NV_DTO.Mabophan = txtMaBoPhan.Text;
            NV_BUS.xoa_NhanVien(NV_DTO);
            frmNhanVien_Load(sender, e);
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            NV_DTO.Manv = txtMaNV.Text;
            NV_DTO.Tennv = txtHoTen.Text;
            NV_DTO.Ngaysinh = dateTimePicker1.Value;
            NV_DTO.Diachi = txtDiaChi.Text;
            NV_DTO.Dienthoai = txtDienThoai.Text;
            NV_DTO.Machucvu = txtMaChucVu.Text;
            NV_DTO.Mabophan = txtMaBoPhan.Text;
            NV_BUS.Sus_NhanVien(NV_DTO);
            frmNhanVien_Load(sender, e);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
       
        private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
        {
           
        }
        int dong;
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            dong = e.RowIndex;
            try
            {
                txtMaNV.Text = dataGridView1.Rows[dong].Cells[0].Value.ToString();
                txtHoTen.Text = dataGridView1.Rows[dong].Cells[1].Value.ToString();
                dateTimePicker1.Value = (DateTime)dataGridView1.Rows[dong].Cells[2].Value;
                txtDiaChi.Text = dataGridView1.Rows[dong].Cells[3].Value.ToString();
                txtDienThoai.Text = dataGridView1.Rows[dong].Cells[4].Value.ToString();
                txtBangCap.Text = dataGridView1.Rows[dong].Cells[5].Value.ToString();
                txtMaBoPhan.Text = dataGridView1.Rows[dong].Cells[6].Value.ToString();
                txtMaChucVu.Text = dataGridView1.Rows[dong].Cells[7].Value.ToString();
            }
            catch 
              {
                  txtMaNV.Text = " ";
                  txtHoTen.Text = " ";
                  //dateTimePicker1.Value = DateTime.;
                  txtDiaChi.Text = " ";
                  txtDienThoai.Text = " ";
                  txtBangCap.Text = " ";
                  txtMaBoPhan.Text =" ";
                  txtMaChucVu.Text = " ";
            
            
              };
            
            }

        private void btnMoi_Click(object sender, EventArgs e)
        {
            txtMaNV.Text = NV_BUS.Phatsinh_MaNV();
            txtHoTen.Text = " ";
            //dateTimePicker1.Value = DateTime.;
            txtDiaChi.Text = " ";
            txtDienThoai.Text = " ";
            txtBangCap.Text = " ";
            txtMaBoPhan.Text = " ";
            txtMaChucVu.Text = " ";
            

        }

        private void btnsearch_Click(object sender, EventArgs e)
        {
            frmTimKiemNV f = new frmTimKiemNV();
            f.Show();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        
        private void btnThoat_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Ban muon thoat khoi chuong trinh??", "thong bao", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
            {
                this.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource= NV_BUS.insert();
            frmNhanVien_Load(sender, e);
        }

        private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {

        }

        

    }
}
